package com.hx.setting.dao.imp;

import com.hx.setting.dao.AbstractJDBCDaoSupport.ResultSetHandler;
import com.hx.setting.dao.BaseDao;
import com.hx.setting.dao.UsersDao;
import com.hx.setting.dao.imp.JdbcBaseDaoImp;
import com.hx.setting.entity.UsersEntity;
import com.hx.setting.entity.UsersEntityWithBLOBs;
import com.hx.setting.model.Condition;
import com.hx.setting.model.GeneratedCriteria.Criterion;
import com.hx.setting.model.GeneratedCriteria;
import com.hx.setting.model.Page;
import com.hx.setting.model.UsersModel;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Generate Date : 2014-03-16
 * Generate Version : v3.0
 * Generate Name : Honey v3.1 Test
 * Generate User : THINK
 * JDK Version : 1.5
 */
@SuppressWarnings("unchecked")
public class UsersDaoImp<E extends UsersEntity, PK extends Long> extends JdbcBaseDaoImp<E, PK> implements UsersDao<E, PK>
{

	private static final String		TABLE_NAME			= "hx_users";

	private static final String		PK_FIELD_NAME		= "id";

	private static final String		BASE_QUERY_FIELD	= "hx_users.id AS id ,hx_users.user_name AS userName ,hx_users.user_password AS userPassword ,hx_users.first_name AS firstName ,hx_users.last_name AS lastName ,hx_users.reports_to_id AS reportsToId ,hx_users.is_admin AS isAdmin ,hx_users.date_entered AS dateEntered ,hx_users.date_modified AS dateModified ,hx_users.modified_user_id AS modifiedUserId ,hx_users.position AS position ,hx_users.department AS department ,hx_users.phone_home AS phoneHome ,hx_users.phone_mobile AS phoneMobile ,hx_users.phone_work AS phoneWork ,hx_users.phone_other AS phoneOther ,hx_users.phone_fax AS phoneFax ,hx_users.email1 AS email1 ,hx_users.email2 AS email2 ,hx_users.status AS status ,hx_users.address_street AS addressStreet ,hx_users.address_city AS addressCity ,hx_users.address_state AS addressState ,hx_users.address_country AS addressCountry ,hx_users.address_postalcode AS addressPostalcode ,hx_users.weekstart AS weekstart ,hx_users.date_format AS dateFormat ,hx_users.hour_format AS hourFormat ,hx_users.start_hour AS startHour ,hx_users.end_hour AS endHour ,hx_users.activity_view AS activityView ,hx_users.lead_view AS leadView ,hx_users.imagename AS imagename ,hx_users.deleted AS deleted ,hx_users.confirm_password AS confirmPassword ,hx_users.internal_mailer AS internalMailer ,hx_users.reminder_interval AS reminderInterval ,hx_users.reminder_next_time AS reminderNextTime ,hx_users.crypt_type AS cryptType ,hx_users.accesskey AS accesskey ,hx_users.theme AS theme ,hx_users.language AS language ,hx_users.time_zone AS timeZone ,hx_users.currency_grouping_pattern AS currencyGroupingPattern ,hx_users.currency_decimal_separator AS currencyDecimalSeparator ,hx_users.currency_grouping_separator AS currencyGroupingSeparator ,hx_users.currency_symbol_placement AS currencySymbolPlacement ,hx_users.no_of_currency_decimals AS noOfCurrencyDecimals ";

	private static final String[]	BASE_FIELD			= new String[]
														{ "id", "userName", "userPassword", "firstName", "lastName", "reportsToId", "isAdmin", "dateEntered", "dateModified",
			"modifiedUserId", "position", "department", "phoneHome", "phoneMobile", "phoneWork", "phoneOther", "phoneFax", "email1", "email2", "status", "addressStreet",
			"addressCity", "addressState", "addressCountry", "addressPostalcode", "weekstart", "dateFormat", "hourFormat", "startHour", "endHour", "activityView", "leadView",
			"imagename", "deleted", "confirmPassword", "internalMailer", "reminderInterval", "reminderNextTime", "cryptType", "accesskey", "theme", "language", "timeZone",
			"currencyGroupingPattern", "currencyDecimalSeparator", "currencyGroupingSeparator", "currencySymbolPlacement", "noOfCurrencyDecimals" };

	private static final String		BLOB_QUERY_FIELD	= "hx_users.description AS description ,hx_users.signature AS signature ,hx_users.user_preferences AS userPreferences ";

	private static final String[]	BLOB_FIELD			= new String[]
														{ "description", "signature", "userPreferences" };

	@Override
	protected String getTableName()
	{
		return TABLE_NAME;
	}

	@Override
	protected String getFieldPrimaryKeyName()
	{
		return PK_FIELD_NAME;
	}

	@Override
	protected ResultSetHandler getResultSetHandler()
	{
		return new UsersDaoImp.QueryResultSetHandler();
	}

	@Override
	protected String[] getBaseField()
	{
		return BASE_FIELD;
	}

	@Override
	protected String[] getBlobField()
	{
		return BLOB_FIELD;
	}

	@Override
	protected String getBaseQueryField()
	{
		return BASE_QUERY_FIELD;
	}

	@Override
	protected String getBlobQueryField()
	{
		return BLOB_QUERY_FIELD;
	}

	@Override
	protected E getEntity(boolean hasBlob)
	{
		UsersEntity answer = null;
		answer = hasBlob ? new UsersEntityWithBLOBs() : new UsersEntity();
		return (E) answer;
	}

	@Override
	public int insert(E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			StringBuilder sql = new StringBuilder( "INSERT INTO " ).append( TABLE_NAME );
			sql
					.append( "( user_name, user_password, first_name, last_name, reports_to_id, is_admin, description, date_entered, date_modified, modified_user_id, position, department, phone_home, phone_mobile, phone_work, phone_other, phone_fax, email1, email2, status, signature, address_street, address_city, address_state, address_country, address_postalcode, user_preferences, weekstart, date_format, hour_format, start_hour, end_hour, activity_view, lead_view, imagename, deleted, confirm_password, internal_mailer, reminder_interval, reminder_next_time, crypt_type, accesskey, theme, language, time_zone, currency_grouping_pattern, currency_decimal_separator, currency_grouping_separator, currency_symbol_placement, no_of_currency_decimals ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" );
			Object[] params = new Object[]
			{ bean.getUserName(), bean.getUserPassword(), bean.getFirstName(), bean.getLastName(), bean.getReportsToId(), bean.getIsAdmin(),
					bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null, bean.getDateEntered(), bean.getDateModified(),
					bean.getModifiedUserId(), bean.getPosition(), bean.getDepartment(), bean.getPhoneHome(), bean.getPhoneMobile(), bean.getPhoneWork(), bean.getPhoneOther(),
					bean.getPhoneFax(), bean.getEmail1(), bean.getEmail2(), bean.getStatus(),
					bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null, bean.getAddressStreet(), bean.getAddressCity(),
					bean.getAddressState(), bean.getAddressCountry(), bean.getAddressPostalcode(),
					bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null, bean.getWeekstart(), bean.getDateFormat(),
					bean.getHourFormat(), bean.getStartHour(), bean.getEndHour(), bean.getActivityView(), bean.getLeadView(), bean.getImagename(), bean.getDeleted(),
					bean.getConfirmPassword(), bean.getInternalMailer(), bean.getReminderInterval(), bean.getReminderNextTime(), bean.getCryptType(), bean.getAccesskey(),
					bean.getTheme(), bean.getLanguage(), bean.getTimeZone(), bean.getCurrencyGroupingPattern(), bean.getCurrencyDecimalSeparator(),
					bean.getCurrencyGroupingSeparator(), bean.getCurrencySymbolPlacement(), bean.getNoOfCurrencyDecimals() };
			try
			{
				GeneratedKeysHandler keyHandler = new GeneratedKeysHandler();
				answer = update( prepareConnection() ,true ,sql.toString() ,keyHandler ,params );
				bean.setId( keyHandler.getGeneratedKeys() );
			}
			catch ( SQLException e )
			{
				e.printStackTrace();
			}
		}
		return answer;
	}

	@Override
	public int insertSelective(E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			StringBuilder sql = new StringBuilder( "INSERT INTO " ).append( TABLE_NAME );
			StringBuilder field = new StringBuilder();
			StringBuilder value = new StringBuilder();
			List params = new ArrayList();
			Object o = null;
			o = bean.getUserName();
			if ( o != null )
			{
				field.append( "user_name, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getUserPassword();
			if ( o != null )
			{
				field.append( "user_password, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getFirstName();
			if ( o != null )
			{
				field.append( "first_name, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getLastName();
			if ( o != null )
			{
				field.append( "last_name, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getReportsToId();
			if ( o != null )
			{
				field.append( "reports_to_id, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getIsAdmin();
			if ( o != null )
			{
				field.append( "is_admin, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null;
			if ( o != null )
			{
				field.append( "description, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getDateEntered();
			if ( o != null )
			{
				field.append( "date_entered, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getDateModified();
			if ( o != null )
			{
				field.append( "date_modified, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getModifiedUserId();
			if ( o != null )
			{
				field.append( "modified_user_id, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPosition();
			if ( o != null )
			{
				field.append( "position, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getDepartment();
			if ( o != null )
			{
				field.append( "department, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPhoneHome();
			if ( o != null )
			{
				field.append( "phone_home, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPhoneMobile();
			if ( o != null )
			{
				field.append( "phone_mobile, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPhoneWork();
			if ( o != null )
			{
				field.append( "phone_work, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPhoneOther();
			if ( o != null )
			{
				field.append( "phone_other, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getPhoneFax();
			if ( o != null )
			{
				field.append( "phone_fax, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getEmail1();
			if ( o != null )
			{
				field.append( "email1, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getEmail2();
			if ( o != null )
			{
				field.append( "email2, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getStatus();
			if ( o != null )
			{
				field.append( "status, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null;
			if ( o != null )
			{
				field.append( "signature, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAddressStreet();
			if ( o != null )
			{
				field.append( "address_street, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAddressCity();
			if ( o != null )
			{
				field.append( "address_city, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAddressState();
			if ( o != null )
			{
				field.append( "address_state, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAddressCountry();
			if ( o != null )
			{
				field.append( "address_country, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAddressPostalcode();
			if ( o != null )
			{
				field.append( "address_postalcode, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null;
			if ( o != null )
			{
				field.append( "user_preferences, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getWeekstart();
			if ( o != null )
			{
				field.append( "weekstart, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getDateFormat();
			if ( o != null )
			{
				field.append( "date_format, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getHourFormat();
			if ( o != null )
			{
				field.append( "hour_format, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getStartHour();
			if ( o != null )
			{
				field.append( "start_hour, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getEndHour();
			if ( o != null )
			{
				field.append( "end_hour, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getActivityView();
			if ( o != null )
			{
				field.append( "activity_view, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getLeadView();
			if ( o != null )
			{
				field.append( "lead_view, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getImagename();
			if ( o != null )
			{
				field.append( "imagename, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getDeleted();
			if ( o != null )
			{
				field.append( "deleted, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getConfirmPassword();
			if ( o != null )
			{
				field.append( "confirm_password, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getInternalMailer();
			if ( o != null )
			{
				field.append( "internal_mailer, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getReminderInterval();
			if ( o != null )
			{
				field.append( "reminder_interval, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getReminderNextTime();
			if ( o != null )
			{
				field.append( "reminder_next_time, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getCryptType();
			if ( o != null )
			{
				field.append( "crypt_type, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getAccesskey();
			if ( o != null )
			{
				field.append( "accesskey, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getTheme();
			if ( o != null )
			{
				field.append( "theme, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getLanguage();
			if ( o != null )
			{
				field.append( "language, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getTimeZone();
			if ( o != null )
			{
				field.append( "time_zone, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingPattern();
			if ( o != null )
			{
				field.append( "currency_grouping_pattern, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getCurrencyDecimalSeparator();
			if ( o != null )
			{
				field.append( "currency_decimal_separator, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingSeparator();
			if ( o != null )
			{
				field.append( "currency_grouping_separator, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getCurrencySymbolPlacement();
			if ( o != null )
			{
				field.append( "currency_symbol_placement, " );
				value.append( "?, " );
				params.add( o );
			}
			o = bean.getNoOfCurrencyDecimals();
			if ( o != null )
			{
				field.append( "no_of_currency_decimals, " );
				value.append( "?, " );
				params.add( o );
			}
			field.deleteCharAt( field.length() - 2 );
			sql.append( "( " ).append( field ).append( ") VALUES (" );
			value.deleteCharAt( value.length() - 2 );
			sql.append( value ).append( ')' );
			try
			{
				GeneratedKeysHandler keyHandler = new GeneratedKeysHandler();
				answer = update( prepareConnection() ,true ,sql.toString() ,keyHandler ,params.toArray() );
				bean.setId( keyHandler.getGeneratedKeys() );
			}
			catch ( SQLException e )
			{
				e.printStackTrace();
			}
		}
		return answer;
	}

	@Override
	public int update(E bean)
	{
		return updateByPrimaryKey( bean );
	}

	@Override
	public int updateByPrimaryKey(E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			String set = ("user_name=? ,user_password=? ,first_name=? ,last_name=? ,reports_to_id=? ,is_admin=? ,description=? ,date_entered=? ,date_modified=? ,modified_user_id=? ,position=? ,department=? ,phone_home=? ,phone_mobile=? ,phone_work=? ,phone_other=? ,phone_fax=? ,email1=? ,email2=? ,status=? ,signature=? ,address_street=? ,address_city=? ,address_state=? ,address_country=? ,address_postalcode=? ,user_preferences=? ,weekstart=? ,date_format=? ,hour_format=? ,start_hour=? ,end_hour=? ,activity_view=? ,lead_view=? ,imagename=? ,deleted=? ,confirm_password=? ,internal_mailer=? ,reminder_interval=? ,reminder_next_time=? ,crypt_type=? ,accesskey=? ,theme=? ,language=? ,time_zone=? ,currency_grouping_pattern=? ,currency_decimal_separator=? ,currency_grouping_separator=? ,currency_symbol_placement=? ,no_of_currency_decimals=?  ");
			answer = update(
								set ,
								"id=? " ,
								new Object[]
								{ bean.getUserName(), bean.getUserPassword(), bean.getFirstName(), bean.getLastName(), bean.getReportsToId(), bean.getIsAdmin(),
										bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null, bean.getDateEntered(),
										bean.getDateModified(), bean.getModifiedUserId(), bean.getPosition(), bean.getDepartment(), bean.getPhoneHome(), bean.getPhoneMobile(),
										bean.getPhoneWork(), bean.getPhoneOther(), bean.getPhoneFax(), bean.getEmail1(), bean.getEmail2(), bean.getStatus(),
										bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null, bean.getAddressStreet(), bean.getAddressCity(),
										bean.getAddressState(), bean.getAddressCountry(), bean.getAddressPostalcode(),
										bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null, bean.getWeekstart(),
										bean.getDateFormat(), bean.getHourFormat(), bean.getStartHour(), bean.getEndHour(), bean.getActivityView(), bean.getLeadView(),
										bean.getImagename(), bean.getDeleted(), bean.getConfirmPassword(), bean.getInternalMailer(), bean.getReminderInterval(),
										bean.getReminderNextTime(), bean.getCryptType(), bean.getAccesskey(), bean.getTheme(), bean.getLanguage(), bean.getTimeZone(),
										bean.getCurrencyGroupingPattern(), bean.getCurrencyDecimalSeparator(), bean.getCurrencyGroupingSeparator(),
										bean.getCurrencySymbolPlacement(), bean.getNoOfCurrencyDecimals(), bean.getId() } );
		}
		return answer;
	}

	public int updateByPrimaryKeySelective(E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			StringBuilder sql = new StringBuilder();
			StringBuilder field = new StringBuilder();
			StringBuilder finalCond = new StringBuilder();
			List params = new ArrayList();
			Object o = null;
			o = bean.getUserName();
			if ( o != null )
			{
				field.append( "user_name=?, " );
				params.add( o );
			}
			o = bean.getUserPassword();
			if ( o != null )
			{
				field.append( "user_password=?, " );
				params.add( o );
			}
			o = bean.getFirstName();
			if ( o != null )
			{
				field.append( "first_name=?, " );
				params.add( o );
			}
			o = bean.getLastName();
			if ( o != null )
			{
				field.append( "last_name=?, " );
				params.add( o );
			}
			o = bean.getReportsToId();
			if ( o != null )
			{
				field.append( "reports_to_id=?, " );
				params.add( o );
			}
			o = bean.getIsAdmin();
			if ( o != null )
			{
				field.append( "is_admin=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null;
			if ( o != null )
			{
				field.append( "description=?, " );
				params.add( o );
			}
			o = bean.getDateEntered();
			if ( o != null )
			{
				field.append( "date_entered=?, " );
				params.add( o );
			}
			o = bean.getDateModified();
			if ( o != null )
			{
				field.append( "date_modified=?, " );
				params.add( o );
			}
			o = bean.getModifiedUserId();
			if ( o != null )
			{
				field.append( "modified_user_id=?, " );
				params.add( o );
			}
			o = bean.getPosition();
			if ( o != null )
			{
				field.append( "position=?, " );
				params.add( o );
			}
			o = bean.getDepartment();
			if ( o != null )
			{
				field.append( "department=?, " );
				params.add( o );
			}
			o = bean.getPhoneHome();
			if ( o != null )
			{
				field.append( "phone_home=?, " );
				params.add( o );
			}
			o = bean.getPhoneMobile();
			if ( o != null )
			{
				field.append( "phone_mobile=?, " );
				params.add( o );
			}
			o = bean.getPhoneWork();
			if ( o != null )
			{
				field.append( "phone_work=?, " );
				params.add( o );
			}
			o = bean.getPhoneOther();
			if ( o != null )
			{
				field.append( "phone_other=?, " );
				params.add( o );
			}
			o = bean.getPhoneFax();
			if ( o != null )
			{
				field.append( "phone_fax=?, " );
				params.add( o );
			}
			o = bean.getEmail1();
			if ( o != null )
			{
				field.append( "email1=?, " );
				params.add( o );
			}
			o = bean.getEmail2();
			if ( o != null )
			{
				field.append( "email2=?, " );
				params.add( o );
			}
			o = bean.getStatus();
			if ( o != null )
			{
				field.append( "status=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null;
			if ( o != null )
			{
				field.append( "signature=?, " );
				params.add( o );
			}
			o = bean.getAddressStreet();
			if ( o != null )
			{
				field.append( "address_street=?, " );
				params.add( o );
			}
			o = bean.getAddressCity();
			if ( o != null )
			{
				field.append( "address_city=?, " );
				params.add( o );
			}
			o = bean.getAddressState();
			if ( o != null )
			{
				field.append( "address_state=?, " );
				params.add( o );
			}
			o = bean.getAddressCountry();
			if ( o != null )
			{
				field.append( "address_country=?, " );
				params.add( o );
			}
			o = bean.getAddressPostalcode();
			if ( o != null )
			{
				field.append( "address_postalcode=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null;
			if ( o != null )
			{
				field.append( "user_preferences=?, " );
				params.add( o );
			}
			o = bean.getWeekstart();
			if ( o != null )
			{
				field.append( "weekstart=?, " );
				params.add( o );
			}
			o = bean.getDateFormat();
			if ( o != null )
			{
				field.append( "date_format=?, " );
				params.add( o );
			}
			o = bean.getHourFormat();
			if ( o != null )
			{
				field.append( "hour_format=?, " );
				params.add( o );
			}
			o = bean.getStartHour();
			if ( o != null )
			{
				field.append( "start_hour=?, " );
				params.add( o );
			}
			o = bean.getEndHour();
			if ( o != null )
			{
				field.append( "end_hour=?, " );
				params.add( o );
			}
			o = bean.getActivityView();
			if ( o != null )
			{
				field.append( "activity_view=?, " );
				params.add( o );
			}
			o = bean.getLeadView();
			if ( o != null )
			{
				field.append( "lead_view=?, " );
				params.add( o );
			}
			o = bean.getImagename();
			if ( o != null )
			{
				field.append( "imagename=?, " );
				params.add( o );
			}
			o = bean.getDeleted();
			if ( o != null )
			{
				field.append( "deleted=?, " );
				params.add( o );
			}
			o = bean.getConfirmPassword();
			if ( o != null )
			{
				field.append( "confirm_password=?, " );
				params.add( o );
			}
			o = bean.getInternalMailer();
			if ( o != null )
			{
				field.append( "internal_mailer=?, " );
				params.add( o );
			}
			o = bean.getReminderInterval();
			if ( o != null )
			{
				field.append( "reminder_interval=?, " );
				params.add( o );
			}
			o = bean.getReminderNextTime();
			if ( o != null )
			{
				field.append( "reminder_next_time=?, " );
				params.add( o );
			}
			o = bean.getCryptType();
			if ( o != null )
			{
				field.append( "crypt_type=?, " );
				params.add( o );
			}
			o = bean.getAccesskey();
			if ( o != null )
			{
				field.append( "accesskey=?, " );
				params.add( o );
			}
			o = bean.getTheme();
			if ( o != null )
			{
				field.append( "theme=?, " );
				params.add( o );
			}
			o = bean.getLanguage();
			if ( o != null )
			{
				field.append( "language=?, " );
				params.add( o );
			}
			o = bean.getTimeZone();
			if ( o != null )
			{
				field.append( "time_zone=?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingPattern();
			if ( o != null )
			{
				field.append( "currency_grouping_pattern=?, " );
				params.add( o );
			}
			o = bean.getCurrencyDecimalSeparator();
			if ( o != null )
			{
				field.append( "currency_decimal_separator=?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingSeparator();
			if ( o != null )
			{
				field.append( "currency_grouping_separator=?, " );
				params.add( o );
			}
			o = bean.getCurrencySymbolPlacement();
			if ( o != null )
			{
				field.append( "currency_symbol_placement=?, " );
				params.add( o );
			}
			o = bean.getNoOfCurrencyDecimals();
			if ( o != null )
			{
				field.append( "no_of_currency_decimals=?, " );
				params.add( o );
			}
			field.deleteCharAt( field.length() - 2 );
			params.add( bean.getId() );
			answer = update( field.toString() ,"id=? " ,params.toArray() );
		}
		return answer;
	}

	@Override
	public int save(E bean)
	{
		return 0;
	}

	@Override
	public int updateByDynamic(Condition<? extends GeneratedCriteria> search, E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			String set = ("user_name=? ,user_password=? ,first_name=? ,last_name=? ,reports_to_id=? ,is_admin=? ,description=? ,date_entered=? ,date_modified=? ,modified_user_id=? ,position=? ,department=? ,phone_home=? ,phone_mobile=? ,phone_work=? ,phone_other=? ,phone_fax=? ,email1=? ,email2=? ,status=? ,signature=? ,address_street=? ,address_city=? ,address_state=? ,address_country=? ,address_postalcode=? ,user_preferences=? ,weekstart=? ,date_format=? ,hour_format=? ,start_hour=? ,end_hour=? ,activity_view=? ,lead_view=? ,imagename=? ,deleted=? ,confirm_password=? ,internal_mailer=? ,reminder_interval=? ,reminder_next_time=? ,crypt_type=? ,accesskey=? ,theme=? ,language=? ,time_zone=? ,currency_grouping_pattern=? ,currency_decimal_separator=? ,currency_grouping_separator=? ,currency_symbol_placement=? ,no_of_currency_decimals=? ");
			Object[] build = make( search );
			answer = update(
								set ,
								(String) build[0] ,
								com.hx.setting.utils.StringUtils.join(
																		new Object[]
																		{ bean.getUserName(), bean.getUserPassword(), bean.getFirstName(), bean.getLastName(),
																				bean.getReportsToId(), bean.getIsAdmin(),
																				bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null,
																				bean.getDateEntered(), bean.getDateModified(), bean.getModifiedUserId(), bean.getPosition(),
																				bean.getDepartment(), bean.getPhoneHome(), bean.getPhoneMobile(), bean.getPhoneWork(),
																				bean.getPhoneOther(), bean.getPhoneFax(), bean.getEmail1(), bean.getEmail2(), bean.getStatus(),
																				bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null,
																				bean.getAddressStreet(), bean.getAddressCity(), bean.getAddressState(), bean.getAddressCountry(),
																				bean.getAddressPostalcode(),
																				bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null,
																				bean.getWeekstart(), bean.getDateFormat(), bean.getHourFormat(), bean.getStartHour(),
																				bean.getEndHour(), bean.getActivityView(), bean.getLeadView(), bean.getImagename(),
																				bean.getDeleted(), bean.getConfirmPassword(), bean.getInternalMailer(), bean.getReminderInterval(),
																				bean.getReminderNextTime(), bean.getCryptType(), bean.getAccesskey(), bean.getTheme(),
																				bean.getLanguage(), bean.getTimeZone(), bean.getCurrencyGroupingPattern(),
																				bean.getCurrencyDecimalSeparator(), bean.getCurrencyGroupingSeparator(),
																				bean.getCurrencySymbolPlacement(), bean.getNoOfCurrencyDecimals() } ,
																		(Object[]) build[1] ) );
		}
		return answer;
	}

	@Override
	public int updateByDynamicSelective(Condition<? extends GeneratedCriteria> search, E bean)
	{
		int answer = 0;
		if ( bean != null )
		{
			StringBuilder set = new StringBuilder();
			List params = new ArrayList();
			Object o = null;
			o = bean.getUserName();
			if ( o != null )
			{
				set.append( "user_name=?, " );
				params.add( o );
			}
			o = bean.getUserPassword();
			if ( o != null )
			{
				set.append( "user_password=?, " );
				params.add( o );
			}
			o = bean.getFirstName();
			if ( o != null )
			{
				set.append( "first_name=?, " );
				params.add( o );
			}
			o = bean.getLastName();
			if ( o != null )
			{
				set.append( "last_name=?, " );
				params.add( o );
			}
			o = bean.getReportsToId();
			if ( o != null )
			{
				set.append( "reports_to_id=?, " );
				params.add( o );
			}
			o = bean.getIsAdmin();
			if ( o != null )
			{
				set.append( "is_admin=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getDescription() : null;
			if ( o != null )
			{
				set.append( "description=?, " );
				params.add( o );
			}
			o = bean.getDateEntered();
			if ( o != null )
			{
				set.append( "date_entered=?, " );
				params.add( o );
			}
			o = bean.getDateModified();
			if ( o != null )
			{
				set.append( "date_modified=?, " );
				params.add( o );
			}
			o = bean.getModifiedUserId();
			if ( o != null )
			{
				set.append( "modified_user_id=?, " );
				params.add( o );
			}
			o = bean.getPosition();
			if ( o != null )
			{
				set.append( "position=?, " );
				params.add( o );
			}
			o = bean.getDepartment();
			if ( o != null )
			{
				set.append( "department=?, " );
				params.add( o );
			}
			o = bean.getPhoneHome();
			if ( o != null )
			{
				set.append( "phone_home=?, " );
				params.add( o );
			}
			o = bean.getPhoneMobile();
			if ( o != null )
			{
				set.append( "phone_mobile=?, " );
				params.add( o );
			}
			o = bean.getPhoneWork();
			if ( o != null )
			{
				set.append( "phone_work=?, " );
				params.add( o );
			}
			o = bean.getPhoneOther();
			if ( o != null )
			{
				set.append( "phone_other=?, " );
				params.add( o );
			}
			o = bean.getPhoneFax();
			if ( o != null )
			{
				set.append( "phone_fax=?, " );
				params.add( o );
			}
			o = bean.getEmail1();
			if ( o != null )
			{
				set.append( "email1=?, " );
				params.add( o );
			}
			o = bean.getEmail2();
			if ( o != null )
			{
				set.append( "email2=?, " );
				params.add( o );
			}
			o = bean.getStatus();
			if ( o != null )
			{
				set.append( "status=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getSignature() : null;
			if ( o != null )
			{
				set.append( "signature=?, " );
				params.add( o );
			}
			o = bean.getAddressStreet();
			if ( o != null )
			{
				set.append( "address_street=?, " );
				params.add( o );
			}
			o = bean.getAddressCity();
			if ( o != null )
			{
				set.append( "address_city=?, " );
				params.add( o );
			}
			o = bean.getAddressState();
			if ( o != null )
			{
				set.append( "address_state=?, " );
				params.add( o );
			}
			o = bean.getAddressCountry();
			if ( o != null )
			{
				set.append( "address_country=?, " );
				params.add( o );
			}
			o = bean.getAddressPostalcode();
			if ( o != null )
			{
				set.append( "address_postalcode=?, " );
				params.add( o );
			}
			o = bean instanceof UsersEntityWithBLOBs ? ((UsersEntityWithBLOBs) bean).getUserPreferences() : null;
			if ( o != null )
			{
				set.append( "user_preferences=?, " );
				params.add( o );
			}
			o = bean.getWeekstart();
			if ( o != null )
			{
				set.append( "weekstart=?, " );
				params.add( o );
			}
			o = bean.getDateFormat();
			if ( o != null )
			{
				set.append( "date_format=?, " );
				params.add( o );
			}
			o = bean.getHourFormat();
			if ( o != null )
			{
				set.append( "hour_format=?, " );
				params.add( o );
			}
			o = bean.getStartHour();
			if ( o != null )
			{
				set.append( "start_hour=?, " );
				params.add( o );
			}
			o = bean.getEndHour();
			if ( o != null )
			{
				set.append( "end_hour=?, " );
				params.add( o );
			}
			o = bean.getActivityView();
			if ( o != null )
			{
				set.append( "activity_view=?, " );
				params.add( o );
			}
			o = bean.getLeadView();
			if ( o != null )
			{
				set.append( "lead_view=?, " );
				params.add( o );
			}
			o = bean.getImagename();
			if ( o != null )
			{
				set.append( "imagename=?, " );
				params.add( o );
			}
			o = bean.getDeleted();
			if ( o != null )
			{
				set.append( "deleted=?, " );
				params.add( o );
			}
			o = bean.getConfirmPassword();
			if ( o != null )
			{
				set.append( "confirm_password=?, " );
				params.add( o );
			}
			o = bean.getInternalMailer();
			if ( o != null )
			{
				set.append( "internal_mailer=?, " );
				params.add( o );
			}
			o = bean.getReminderInterval();
			if ( o != null )
			{
				set.append( "reminder_interval=?, " );
				params.add( o );
			}
			o = bean.getReminderNextTime();
			if ( o != null )
			{
				set.append( "reminder_next_time=?, " );
				params.add( o );
			}
			o = bean.getCryptType();
			if ( o != null )
			{
				set.append( "crypt_type=?, " );
				params.add( o );
			}
			o = bean.getAccesskey();
			if ( o != null )
			{
				set.append( "accesskey=?, " );
				params.add( o );
			}
			o = bean.getTheme();
			if ( o != null )
			{
				set.append( "theme=?, " );
				params.add( o );
			}
			o = bean.getLanguage();
			if ( o != null )
			{
				set.append( "language=?, " );
				params.add( o );
			}
			o = bean.getTimeZone();
			if ( o != null )
			{
				set.append( "time_zone=?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingPattern();
			if ( o != null )
			{
				set.append( "currency_grouping_pattern=?, " );
				params.add( o );
			}
			o = bean.getCurrencyDecimalSeparator();
			if ( o != null )
			{
				set.append( "currency_decimal_separator=?, " );
				params.add( o );
			}
			o = bean.getCurrencyGroupingSeparator();
			if ( o != null )
			{
				set.append( "currency_grouping_separator=?, " );
				params.add( o );
			}
			o = bean.getCurrencySymbolPlacement();
			if ( o != null )
			{
				set.append( "currency_symbol_placement=?, " );
				params.add( o );
			}
			o = bean.getNoOfCurrencyDecimals();
			if ( o != null )
			{
				set.append( "no_of_currency_decimals=?, " );
				params.add( o );
			}
			set.deleteCharAt( set.length() - 2 );
			Object[] build = make( search );
			answer = update( set.toString() ,(String) build[0] ,com.hx.setting.utils.StringUtils.join( params.toArray() ,(Object[]) build[1] ) );
		}
		return answer;
	}

	/** 
	 * 按照时间(dateEntered)区间查询
	 * @param start 开始时间
	 * @param end 结束时间
	 * @return 返回影响的记录集数量
	 */
	@Override
	public List<E> selectByDateEntered(Date start, Date end)
	{
		List<E> answer = null;
		Condition gje = new Condition( new UsersModel() );
		gje.or().andBetween( UsersModel.UsersTableField.DATEENTERED ,start ,end );
		answer = selectByDynamic( gje ,new Page( 0, 1 ) );
		return answer;
	}

	/** 
	 * 按照时间(dateEntered)区间查询
	 * @param start 开始时间
	 * @param end 结束时间
	 * @return 返回影响的记录集数量
	 */
	@Override
	public List<E> selectByDateEntered(Date start, Date end, Page page)
	{
		List<E> answer = null;
		Condition gni = new Condition( new UsersModel() );
		gni.or().andBetween( UsersModel.UsersTableField.DATEENTERED ,start ,end );
		answer = selectByDynamic( gni ,page );
		return answer;
	}

	/** 
	 * 按照时间(dateModified)区间查询
	 * @param start 开始时间
	 * @param end 结束时间
	 * @return 返回影响的记录集数量
	 */
	@Override
	public List<E> selectByDateModified(Date start, Date end)
	{
		List<E> answer = null;
		Condition kng = new Condition( new UsersModel() );
		kng.or().andBetween( UsersModel.UsersTableField.DATEMODIFIED ,start ,end );
		answer = selectByDynamic( kng ,new Page( 0, 1 ) );
		return answer;
	}

	/** 
	 * 按照时间(dateModified)区间查询
	 * @param start 开始时间
	 * @param end 结束时间
	 * @return 返回影响的记录集数量
	 */
	@Override
	public List<E> selectByDateModified(Date start, Date end, Page page)
	{
		List<E> answer = null;
		Condition agi = new Condition( new UsersModel() );
		agi.or().andBetween( UsersModel.UsersTableField.DATEMODIFIED ,start ,end );
		answer = selectByDynamic( agi ,page );
		return answer;
	}

	private class QueryResultSetHandler implements ResultSetHandler
	{

		@Override
		public UsersEntity handle(ResultSet resultSet, boolean hasBlob) throws SQLException
		{
			UsersEntity bean = null;
			if ( resultSet.next() )
			{
				bean = hasBlob ? new UsersEntityWithBLOBs() : new UsersEntity();
				Object obj = null;
				obj = resultSet.getLong( "id" );
				if ( obj != null && !resultSet.wasNull() ) bean.setId( (Long) obj );
				obj = resultSet.getString( "userName" );
				if ( obj != null && !resultSet.wasNull() ) bean.setUserName( (String) obj );
				obj = resultSet.getString( "userPassword" );
				if ( obj != null && !resultSet.wasNull() ) bean.setUserPassword( (String) obj );
				obj = resultSet.getString( "firstName" );
				if ( obj != null && !resultSet.wasNull() ) bean.setFirstName( (String) obj );
				obj = resultSet.getString( "lastName" );
				if ( obj != null && !resultSet.wasNull() ) bean.setLastName( (String) obj );
				obj = resultSet.getString( "reportsToId" );
				if ( obj != null && !resultSet.wasNull() ) bean.setReportsToId( (String) obj );
				obj = resultSet.getString( "isAdmin" );
				if ( obj != null && !resultSet.wasNull() ) bean.setIsAdmin( (String) obj );
				obj = resultSet.getTimestamp( "dateEntered" );
				if ( obj != null && !resultSet.wasNull() ) bean.setDateEntered( (java.sql.Timestamp) obj );
				obj = resultSet.getTimestamp( "dateModified" );
				if ( obj != null && !resultSet.wasNull() ) bean.setDateModified( (java.sql.Timestamp) obj );
				obj = resultSet.getString( "modifiedUserId" );
				if ( obj != null && !resultSet.wasNull() ) bean.setModifiedUserId( (String) obj );
				obj = resultSet.getString( "position" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPosition( (String) obj );
				obj = resultSet.getString( "department" );
				if ( obj != null && !resultSet.wasNull() ) bean.setDepartment( (String) obj );
				obj = resultSet.getString( "phoneHome" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPhoneHome( (String) obj );
				obj = resultSet.getString( "phoneMobile" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPhoneMobile( (String) obj );
				obj = resultSet.getString( "phoneWork" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPhoneWork( (String) obj );
				obj = resultSet.getString( "phoneOther" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPhoneOther( (String) obj );
				obj = resultSet.getString( "phoneFax" );
				if ( obj != null && !resultSet.wasNull() ) bean.setPhoneFax( (String) obj );
				obj = resultSet.getString( "email1" );
				if ( obj != null && !resultSet.wasNull() ) bean.setEmail1( (String) obj );
				obj = resultSet.getString( "email2" );
				if ( obj != null && !resultSet.wasNull() ) bean.setEmail2( (String) obj );
				obj = resultSet.getString( "status" );
				if ( obj != null && !resultSet.wasNull() ) bean.setStatus( (String) obj );
				obj = resultSet.getString( "addressStreet" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAddressStreet( (String) obj );
				obj = resultSet.getString( "addressCity" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAddressCity( (String) obj );
				obj = resultSet.getString( "addressState" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAddressState( (String) obj );
				obj = resultSet.getString( "addressCountry" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAddressCountry( (String) obj );
				obj = resultSet.getString( "addressPostalcode" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAddressPostalcode( (String) obj );
				obj = resultSet.getInt( "weekstart" );
				if ( obj != null && !resultSet.wasNull() ) bean.setWeekstart( (Integer) obj );
				obj = resultSet.getString( "dateFormat" );
				if ( obj != null && !resultSet.wasNull() ) bean.setDateFormat( (String) obj );
				obj = resultSet.getString( "hourFormat" );
				if ( obj != null && !resultSet.wasNull() ) bean.setHourFormat( (String) obj );
				obj = resultSet.getString( "startHour" );
				if ( obj != null && !resultSet.wasNull() ) bean.setStartHour( (String) obj );
				obj = resultSet.getString( "endHour" );
				if ( obj != null && !resultSet.wasNull() ) bean.setEndHour( (String) obj );
				obj = resultSet.getString( "activityView" );
				if ( obj != null && !resultSet.wasNull() ) bean.setActivityView( (String) obj );
				obj = resultSet.getString( "leadView" );
				if ( obj != null && !resultSet.wasNull() ) bean.setLeadView( (String) obj );
				obj = resultSet.getString( "imagename" );
				if ( obj != null && !resultSet.wasNull() ) bean.setImagename( (String) obj );
				obj = resultSet.getInt( "deleted" );
				if ( obj != null && !resultSet.wasNull() ) bean.setDeleted( (Integer) obj );
				obj = resultSet.getString( "confirmPassword" );
				if ( obj != null && !resultSet.wasNull() ) bean.setConfirmPassword( (String) obj );
				obj = resultSet.getString( "internalMailer" );
				if ( obj != null && !resultSet.wasNull() ) bean.setInternalMailer( (String) obj );
				obj = resultSet.getString( "reminderInterval" );
				if ( obj != null && !resultSet.wasNull() ) bean.setReminderInterval( (String) obj );
				obj = resultSet.getString( "reminderNextTime" );
				if ( obj != null && !resultSet.wasNull() ) bean.setReminderNextTime( (String) obj );
				obj = resultSet.getString( "cryptType" );
				if ( obj != null && !resultSet.wasNull() ) bean.setCryptType( (String) obj );
				obj = resultSet.getString( "accesskey" );
				if ( obj != null && !resultSet.wasNull() ) bean.setAccesskey( (String) obj );
				obj = resultSet.getString( "theme" );
				if ( obj != null && !resultSet.wasNull() ) bean.setTheme( (String) obj );
				obj = resultSet.getString( "language" );
				if ( obj != null && !resultSet.wasNull() ) bean.setLanguage( (String) obj );
				obj = resultSet.getString( "timeZone" );
				if ( obj != null && !resultSet.wasNull() ) bean.setTimeZone( (String) obj );
				obj = resultSet.getString( "currencyGroupingPattern" );
				if ( obj != null && !resultSet.wasNull() ) bean.setCurrencyGroupingPattern( (String) obj );
				obj = resultSet.getString( "currencyDecimalSeparator" );
				if ( obj != null && !resultSet.wasNull() ) bean.setCurrencyDecimalSeparator( (String) obj );
				obj = resultSet.getString( "currencyGroupingSeparator" );
				if ( obj != null && !resultSet.wasNull() ) bean.setCurrencyGroupingSeparator( (String) obj );
				obj = resultSet.getString( "currencySymbolPlacement" );
				if ( obj != null && !resultSet.wasNull() ) bean.setCurrencySymbolPlacement( (String) obj );
				obj = resultSet.getString( "noOfCurrencyDecimals" );
				if ( obj != null && !resultSet.wasNull() ) bean.setNoOfCurrencyDecimals( (String) obj );
				if ( hasBlob )
				{
					UsersEntityWithBLOBs b = (UsersEntityWithBLOBs) bean;
					b.setDescription( resultSet.getString( "description" ) );
					b.setSignature( resultSet.getString( "signature" ) );
					b.setUserPreferences( resultSet.getString( "userPreferences" ) );
				}
			}
			return bean;
		}
	}
}
/* Honey v3.1 Test - version:4 - OriginalChecksum:Bf9e26b7facd277013b39dc6a99b278da (do not edit this line) */
